from flask import Flask
from flask_restful import Resource,Api,fields,marshal_with

app = Flask(__name__)
api = Api(app)

class News:
    def __init__(self,code,msg,content):
        self.code=code
        self.msg = msg
        self.info = content

class NewsView(Resource):
    resource_fields = {
        'code':fields.Integer(default=200), #通过参数default设置默认值
        'msg':fields.String,
        'content':fields.String(attribute='info')  #通过attribute设置提取数据的字段
    }
    @marshal_with(resource_fields)
    def get(self):
        news = News(200,'访问成功','移动')
        return news



api.add_resource(NewsView,'/news/')

if __name__ == '__main__':
    app.run(debug=True)